bitkeeper revision 1.1159.1.36 (4119f27eonzahatd09ja80xf3ifOFw)
authormjw@wray-m-3.hpl.hp.com <mjw@wray-m-3.hpl.hp.com>
Wed, 11 Aug 2004 10:18:38 +0000 (10:18 +0000)
committermjw@wray-m-3.hpl.hp.com <mjw@wray-m-3.hpl.hp.com>
Wed, 11 Aug 2004 10:18:38 +0000 (10:18 +0000)
Documentation and some debug changes.

tools/python/xen/xend/XendDomainInfo.py
tools/python/xen/xend/server/blkif.py
tools/python/xen/xend/server/controller.py
tools/python/xen/xend/server/messages.py
tools/python/xen/xend/server/netif.py

index 0df3c2208ae06c915420cdac75356d3bd94180f2..472cc0f74c8fb73e7428a33050b8656f16a59823 100644 (file)
@@ -472,7 +472,10 @@ class XendDomainInfo:
         # When creating or rebooting, a domain with my name should not exist.
         # When restoring, a domain with my name will exist, but it should have
         # my domain id.
-        if dominfo and (not self.dom or dominfo.dom != self.dom):
+        if not dominfo:
+            return
+        print 'check_name>', 'dom=', dominfo.name, dominfo.dom, 'self=', name, self.dom
+        if not self.dom or (dominfo.dom != self.dom):
             raise VmError('vm name clash: ' + name)
         
     def construct(self, config):
index 192871d12448e341b0760427eec199993df84710..cace931afccacb8d5d0d5dbfd96976599171ce1b 100755 (executable)
@@ -1,4 +1,6 @@
 # Copyright (C) 2004 Mike Wray <mike.wray@hp.com>
+"""Support for virtual block devices.
+"""
 
 from twisted.internet import defer
 #defer.Deferred.debug = 1
index fdc8bfc0ac678a116f18c676fc30380dd371d45b..e40b72cc885aaa16fabb8f369e5bc3e81a2bd2c6 100755 (executable)
@@ -247,7 +247,7 @@ class ControllerFactory(CtrlMsgRcvr):
     Maintains a table of instances.
 
     @ivar instances: mapping of index to controller instance
-    @type instances: {int: Controller}
+    @type instances: {String: Controller}
     @ivar dom: domain
     @type dom: int
     """
@@ -274,6 +274,10 @@ class ControllerFactory(CtrlMsgRcvr):
 
     def getInstanceByDom(self, dom):
         """Get the controller instance for the given domain.
+
+        @param dom: domain id
+        @type  dom: int
+        @return: controller or None
         """
         for inst in self.instances.values():
             if inst.dom == dom:
@@ -281,7 +285,9 @@ class ControllerFactory(CtrlMsgRcvr):
         return None
 
     def delInstance(self, instance):
-        """Delete an instance from the table.
+        """Delete a controller instance from the table.
+
+        @param instance: controller instance
         """
         if instance.idx in self.instances:
             del self.instances[instance.idx]
@@ -293,16 +299,29 @@ class ControllerFactory(CtrlMsgRcvr):
         @type  dom: int
         @param recreate: true if the instance is being recreated (after xend restart)
         @type  recreate: int
+        @return: controller instance
+        @rtype:  Controller (or subclass)
         """
         raise NotImplementedError()
 
     def instanceClosed(self, instance):
         """Callback called when an instance is closed (usually by the instance).
+        
+        @param instance: controller instance
         """
         self.delInstance(instance)
 
 class Controller(CtrlMsgRcvr):
     """Abstract class for a device controller attached to a domain.
+
+    @ivar factory: controller factory
+    @type factory: ControllerFactory
+    @ivar dom:     domain
+    @type dom:     int
+    @ivar channel: channel to the domain
+    @type channel: Channel
+    @ivar idx:     channel index
+    @type idx:     String
     """
 
     def __init__(self, factory, dom):
@@ -325,6 +344,13 @@ class Controller(CtrlMsgRcvr):
 
 class Dev:
     """Abstract class for a device attached to a device controller.
+
+    @ivar idx:        identifier
+    @type idx:        String
+    @ivar controller: device controller
+    @type controller: DeviceController
+    @ivar props:      property table
+    @type props:      { String: value }
     """
     
     def __init__(self, idx, controller):
@@ -349,6 +375,11 @@ class Dev:
             del self.props[k]
 
     def sxpr(self):
+        """Get the s-expression for the deivice.
+        Implement in a subclass.
+
+        @return: sxpr
+        """
         raise NotImplementedError()
 
     
index 92b26091b28f589991534b2e0f4f420e38d280cf..c61d3598aef5b21f9b55daf8ba59987bd37384fb 100644 (file)
@@ -213,9 +213,6 @@ def packMsg(ty, params):
                 args['mac[%d]' % i] = v[i]
         else:
             args[k] = v
-    if DEBUG:
-        for (k, v) in args.items():
-            print 'packMsg>', k, v, type(v)
     msg = xu.message(major, minor, msgid, args)
     if DEBUG: print '<packMsg', msg.get_header()['id'], ty, params
     return msg
index 91601891209c16f4835e715a7efd8bf8416cab9a..d78979c992bb32db571455dc5dd0f2af11e0b31f 100755 (executable)
@@ -1,4 +1,6 @@
 # Copyright (C) 2004 Mike Wray <mike.wray@hp.com>
+"""Support for virtual network interfaces.
+"""
 
 import random
 
@@ -27,8 +29,6 @@ class NetifControllerFactory(controller.ControllerFactory):
         self.majorTypes = [ CMSG_NETIF_BE ]
 
         self.subTypes = {
-            #CMSG_NETIF_BE_CREATE : self.recv_be_create,
-            #CMSG_NETIF_BE_CONNECT: self.recv_be_connect,
             CMSG_NETIF_BE_DRIVER_STATUS_CHANGED: self.recv_be_driver_status_changed,
             }
         self.attached = 1
@@ -37,10 +37,9 @@ class NetifControllerFactory(controller.ControllerFactory):
     def createInstance(self, dom, recreate=0):
         """Create or find the network interface controller for a domain.
 
-        dom      domain
-        recreate if true this is a recreate (xend restarted)
-
-        returns netif controller
+        @param dom:      domain
+        @param recreate: if true this is a recreate (xend restarted)
+        @return: netif controller
         """
         netif = self.getInstanceByDom(dom)
         if netif is None:
@@ -51,9 +50,8 @@ class NetifControllerFactory(controller.ControllerFactory):
     def getDomainDevices(self, dom):
         """Get the network device controllers for a domain.
 
-        dom  domain
-        
-        returns netif controller
+        @param dom:  domain
+        @return: netif controller list
         """
         netif = self.getInstanceByDom(dom)
         return (netif and netif.getDevices()) or []
@@ -61,10 +59,9 @@ class NetifControllerFactory(controller.ControllerFactory):
     def getDomainDevice(self, dom, vif):
         """Get a virtual network interface device for a domain.
 
-        dom domain
-        vif virtual interface index
-
-        returns NetDev
+        @param dom: domain
+        @param vif: virtual interface index
+        @return: NetDev
         """
         netif = self.getInstanceByDom(dom)
         return (netif and netif.getDevice(vif)) or None
@@ -72,8 +69,8 @@ class NetifControllerFactory(controller.ControllerFactory):
     def setControlDomain(self, dom, recreate=0):
         """Set the 'back-end' device driver domain.
 
-        dom      domain
-        recreate if true this is a recreate (xend restarted)
+        @param dom:     domain
+        @param recreate: if true this is a recreate (xend restarted)
         """
         if self.dom == dom: return
         self.deregisterChannel()
@@ -84,6 +81,8 @@ class NetifControllerFactory(controller.ControllerFactory):
 
     def getControlDomain(self):
         """Get the domain id of the back-end control domain.
+
+        @return domain id
         """
         return self.dom
 
@@ -95,7 +94,7 @@ class NetifControllerFactory(controller.ControllerFactory):
         if netif:
             netif.send_interface_connected(vif)
         else:
-            log.warning("respond_be_connect> unknown dom=%d vif=%d", dom, vif)
+            log.warning("respond_be_connect> unknown vif dom=%d vif=%d", dom, vif)
             pass
 
     def recv_be_driver_status_changed(self, msg, req):
@@ -168,6 +167,8 @@ class NetDev(controller.Dev):
         return ':'.join(map(lambda x: "%02x" % x, self.mac))
 
     def vifctl_params(self, vmname=None):
+        """Get the parameters to pass to vifctl.
+        """
         dom = self.controller.dom
         if vmname is None:
             xd = get_component('xen.xend.XendDomain')
@@ -185,6 +186,11 @@ class NetDev(controller.Dev):
 
     def vifctl(self, op, vmname=None):
         """Bring the device up or down.
+        The vmname is needed when bringing a device up for a new domain because
+        the domain is not yet in the table so we can't look its name up.
+
+        @param op: operation name (up, down)
+        @param vmname: vmname
         """
         Vifctl.vifctl(op, **self.vifctl_params(vmname=vmname))
         vnet = XendVnet.instance().vnet_of_bridge(self.bridge)
@@ -239,19 +245,17 @@ class NetifController(controller.Controller):
     def getDevice(self, vif):
         """Get a device.
 
-        vif device index
-
-        returns device (or None)
+        @param vif: device index
+        @return: device (or None)
         """
         return self.devices.get(vif)
 
     def addDevice(self, vif, config):
         """Add a network interface.
 
-        vif device index
-        config device configuration 
-
-        returns device
+        @param vif: device index
+        @param config: device configuration 
+        @return: device
         """
         dev = NetDev(self, vif, config)
         self.devices[vif] = dev
@@ -263,15 +267,18 @@ class NetifController(controller.Controller):
         self.destroyDevices()
         
     def destroyDevices(self):
+        """Destroy all devices.
+        """
         for dev in self.getDevices():
             dev.destroy()
 
     def attachDevice(self, vif, config, recreate=0):
         """Attach a network device.
-        If vmac is None a random mac address is assigned.
 
-        @param vif interface index
-        @param vmac mac address (string)
+        @param vif: interface index
+        @param config: device configuration
+        @param recreate: recreate flag (true after xend restart)
+        @return: deferred
         """
         self.addDevice(vif, config)
         d = defer.Deferred()